#ifndef ELCHECKBOX_H
#define ELCHECKBOX_H

#include "../basic/elabstractbutton.h"

class ElCheckbox : public ElAbstractButton
{
    Q_OBJECT
public:
    ElCheckbox(QWidget *parent = nullptr);
    ElCheckbox(const QString text, QWidget *parent = nullptr);

    Qt::CheckState checkState() const;
    void setCheckState(Qt::CheckState checkState);

    bool isTristate() const;
    void setTristate(bool tristate);

    bool hasBorder() const;
    void setBorder(bool b);

signals:
    void checkStateChanged(Qt::CheckState checkState);

protected:
    Qt::CheckState _checkState = Qt::Unchecked;
    bool _border = false;
    bool _tristate = false;
    QRectF _box;

    bool event(QEvent *e) override;
    void paintEvent(QPaintEvent *e) override;
    void enterEvent(QEnterEvent *e) override;
    void leaveEvent(QEvent *e) override;
    void mousePressEvent(QMouseEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *e) override;
    void initPalette() override;

    void drawBorder(QPainter *painter);
    void drawChecked(QPainter *painter);
    void drawPartiallyChecked(QPainter *painter);

private:
    Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState NOTIFY
                   checkStateChanged FINAL)
};

#endif // ELCHECKBOX_H
